package com.egao.common.manage.company;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.company.constants.CompanyConstants;
import com.egao.common.module.company.entity.vo.PreachCloudFormVO;
import com.egao.common.module.company.entity.vo.PreachCloudListVO;
import com.egao.common.module.company.service.PreachCloudService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 单位空中宣讲会管理
 * @author dl
 */
@Api(tags = "单位空中宣讲会管理")
@RestController
@RequestMapping("${api}")
public class CompanyPreachCloudController extends BaseController {

    @Autowired
    private PreachCloudService preachCloudService;

    @PreAuthorize("hasAuthority('company')")
    @ApiOperation(value = "空中宣讲会信息", notes = "未审核状态升序 创建时间倒序")
    @OperLog(value = "空中宣讲会信息", desc = "分页查询空中宣讲会信息")
    @ApiPageParam
    @GetMapping("/company/preach-cloud/page")
    public PageResult<PreachCloudListVO> page(HttpServletRequest request) {
        PageParam<PreachCloudListVO> pageParam = new PageParam<>(request);
        pageParam.put("user_id", getLoginUserId());
        return new PageResult<>(preachCloudService.listPage(pageParam), pageParam.getTotal());
    }

    @PreAuthorize("hasAuthority('company')")
    @OperLog(value = "添加空中宣讲会信息", desc = "添加空中宣讲会信息", result = true)
    @ApiOperation(value = "添加空中宣讲会信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "preachCloudFormVO", value = "preachCloudFormVO", required = true, dataType = "PreachCloudFormVO")
    })
    @PostMapping("/company/preach-cloud/save")
    public JsonResult save(@Valid @RequestBody PreachCloudFormVO preachCloudFormVO) {
        preachCloudFormVO.setCreateBy(getLoginUserId());
        // 设置空中宣讲会信息为待审核
        preachCloudFormVO.setState(CompanyConstants.RECRUIT_STATE_DSH);
        return preachCloudService.savePreachCloud(preachCloudFormVO);
    }

    @PreAuthorize("hasAuthority('company')")
    @OperLog(value = "修改空中宣讲会信息", desc = "修改空中宣讲会信息", result = true)
    @ApiOperation(value = "修改空中宣讲会信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "preachCloudFormVO", value = "preachCloudFormVO", required = true, dataType = "PreachCloudFormVO")
    })
    @PutMapping("/company/preach-cloud/update")
    public JsonResult update(@Valid @RequestBody PreachCloudFormVO preachCloudFormVO) {
        return preachCloudService.updatePreachCloud(preachCloudFormVO);
    }

    @PreAuthorize("hasAuthority('company')")
    @OperLog(value = "取消空中宣讲会信息", desc = "取消空中宣讲会信息", result = true)
    @ApiOperation(value = "取消空中宣讲会信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "preachCloudFormVO", value = "preachCloudFormVO", required = true, dataType = "PreachCloudFormVO")
    })
    @PutMapping("/company/preach-cloud/cancel")
    public JsonResult cancel(@Valid @RequestBody PreachCloudFormVO preachCloudFormVO) {
        return preachCloudService.cancelPreachCloud(preachCloudFormVO);
    }

    @PreAuthorize("hasAuthority('company')")
    @OperLog(value = "删除空中宣讲会信息", desc = "删除空中宣讲会信息", result = true)
    @ApiOperation(value = "删除空中宣讲会信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "preachCloudFormVO", value = "preachCloudFormVO", required = true, dataType = "PreachCloudFormVO")
    })
    @PutMapping("/company/preach-cloud/delete")
    public JsonResult deletePreach(@RequestBody PreachCloudFormVO preachCloudFormVO) {
        return preachCloudService.removePreachCloud(preachCloudFormVO);
    }

    @PreAuthorize("hasAuthority('company')")
    @ApiOperation(value = "获取空中宣讲会信息详情")
    @OperLog(value = "获取空中宣讲会信息详情", desc = "获取空中宣讲会信息详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "空中宣讲会信息id", required = true, dataType = "int")
    })
    @GetMapping("/company/preach-cloud/detail")
    public JsonResult detail(Integer id) {
        return preachCloudService.detail(id);
    }
}
